from typing import List, Tuple
import sys
def LMI() -> List[int]:
    """Read multiple integers from input"""
    return list(map(int, input().split()))

def LMF() -> List[float]:
    """Read multiple floats from input"""
    return list(map(float, input().split()))

def LI(n: int) -> List[str]:
    """Read n strings from input"""
    return [input() for _ in range(n)]

def RIM(rows: int, cols: int) -> List[List[int]]:
    """Read a matrix of integers"""
    return [LMI() for _ in range(rows)]

def MII():
    """Read multiple integers from input as a map"""
    return map(int, sys.stdin.readline().split())

def II():
    """Read a single integer from input"""
    return int(sys.stdin.readline())

def FI():
    """Read a single float from input"""
    return float(sys.stdin.readline())

        
def solve() -> None:
    def find(n):
        l=1
        r = 1000000
        while l<r:
            mid = (l+r)//2
            if (mid+1)*mid//2>=n:
                r = mid
            else:
                l = mid+1
        return r
    def ans(n):
        return n*(n+1)*(n+2)//6
    def colans(n):
        return n*(n+1)//2
    
    try:
        t = II()
        outs = []
        for _ in range(t):
            l,r = MII()
            bl = l-colans(find(l)-1)
            br = r-colans(find(r)-1)
            ans1 = ans(find(l)-1)+bl*(bl-1)//2
            ans2 = ans(find(r)-1)+br*(br+1)//2
            outs.append(ans2-ans1)
        print('\n'.join(map(str,outs)))
       
    except (EOFError, KeyboardInterrupt):
        pass

# =============================================================================
# MAIN EXECUTION
# =============================================================================

if __name__ == "__main__":
    # For multiple test cases, uncomment:
    # t = int(input())
    # for _ in range(t):
    #     solve()
    
    # For single test case:
    solve()